/**
 * Created by John on 2016/7/8.
 */
function displayWords(skip, cursor) {
    print("Page: " + parseInt(skip + 1) + " to " + parseInt(skip + cursor.size()));
    var words = cursor.map(function (word) {
        return word.word;
    });
    var wordStr = JSON.stringify(words);
    if (wordStr.length > 33) {
        wordStr = wordStr.slice(0, 30) + "...";
    }
    print(wordStr);
}

var mongo = new Mongo("localhost");
var wordsDB = mongo.getDB("BeginningMongoDB");
wordsColl = wordsDB.getCollection("word_stats");

var cursor = wordsColl.find({first: 'w'});
var count = cursor.size();
var skip = 0;
var item = 6;

for (var i = 0; i < count; i += item) {
    cursor = wordsColl.find({first: 'w'});
    cursor.skip(skip);
    cursor.limit(item);
    displayWords(skip, cursor);
    skip += item;
}